<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container mt-1">
          <el-form inline size="small">
            <el-button type="primary" size="mini" @click="addBtn">新增</el-button>
          </el-form>
        </div>
      </div>
      <el-table
        :data="list"
        style="width: 100%"
        size="mini"
        height="500px"
        :highlight-current-row="true"
        :header-cell-style=" {fontWeight:'bold'}"
      >
        <el-table-column
          prop="id"
          label="ID"
          min-width="50"
        />
        <el-table-column label="群组名称"
                         prop="group_name"
                         min-width="100"
                         :show-overflow-tooltip="true">
		
        </el-table-column>
		<el-table-column label="所属人"
		                 prop="owner_name"
		                 min-width="100"
		                 :show-overflow-tooltip="true">
		</el-table-column>
		<el-table-column label="群id"
		                 prop="group_id"
						 width="300"
		                 :show-overflow-tooltip="true">
		</el-table-column>
        <el-table-column
          label="添加时间"
          min-width="120"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.add_time }}</span>
          </template>
        </el-table-column>
		<el-table-column
		  label="更新时间"
		  min-width="120"
		  align="center"
		>
		  <template slot-scope="scope">
		    <span>{{ scope.row.update_time }}</span>
		  </template>
		</el-table-column>
		
        <el-table-column label="操作" min-width="130" fixed="right">
          <template slot-scope="scope">
			<el-button type="text" @click="editRow(scope.row)">编辑</el-button>
			<el-button type="text" @click="delRow(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
	  <div class="page">
	              <el-pagination
	                      background
	                      @size-change="pageChange"
	                      @current-change="handleCurrentChange"
	                      :current-page="page"
	                      :page-size="pageSize"
	                      layout="total, sizes, prev, pager, next, jumper"
	                      :total="page_totle">
	              </el-pagination>
	          </div>
    </el-card>
	
	<!-- 新增角色 -->
	<el-dialog
	  :title="title"
	  :visible.sync="formShow"
	  :close-on-click-modal="false"
	  width="500px">
	  <el-form ref="form" :model="form" label-width="120px">
		  <el-form-item label="归属人">
		  		  	  <el-select v-model="form.owner_id" @change="lodeQyGroupID"  size="small" placeholder="请选择">
		  		  	      <el-option
		  		  	        v-for="item in shopUser"
		  		  	        :key="item.id"
		  		  	        :label="item.name"
		  		  	        :value="item.id">
		  		  	      </el-option>
		  		  	    </el-select>
		  </el-form-item>
		  <el-form-item label="群id">
		  		<el-select v-model="form.group_id" @change="lodeQyGroupInfo"  size="small" placeholder="请选择">
					  <el-option
						v-for="item in group_chat_list"
						:key="item.chat_id"
						:label="item.chat_id"
						:value="item.chat_id">
					  </el-option>
		  		</el-select>
		  </el-form-item>
		  <el-form-item label="群组名称">
		    <el-input size="small" disabled v-model="form.group_name"></el-input>
		  </el-form-item>
	  </el-form>
	  <span slot="footer" class="dialog-footer">
	    <el-button size="mini" @click="formShow = false">取 消</el-button>
	    <el-button size="mini" type="primary" @click="confirm">确 定</el-button>
	  </span>
	</el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        title:'新增',
		isShow:false,
		form:{
			id:null,
			group_name:"",
			owner_id:"",
			group_id:''
		},
		list:[],
		page:1,
		pageSize:10,
		table_name:"customer_group",
		shopUser:[],
		userList:[],
		groupList:[],
		group_chat_list:[],
		group_chat:{
			name:""
		}
      }
    },
    mounted() {
      this.lodeList()
	  this.lodeStaffList()
	  this.lodeQyUserList()
    },
    methods: {
		lodeQyGroupInfo(chartId){
			this.group_id = chartId
			this.$api.post('/sadmin/getGroupInfo',{chartId:chartId}).then(res=>{
				let result = res.data
				if(result.errcode==0){
					this.form.group_name = result.group_chat.name
				}
			})
		},
		lodeQyGroupID(id){
			this.$api.post('/sadmin/getGroupList',{id:id}).then(res=>{
				let result = res.data
				if(result.errcode==0){
					this.group_chat_list = result.group_chat_list
				}
			})
		},
		lodeQyUserList(){
			this.$api.post('/sadmin/getQyUserList',{}).then(res=>{
				let result = res.data
				if(result.errcode==0){
					this.userList = result.userlist
				}
			})
		},
		lodeStaffList(){
				 
			this.$api.post('/sadmin/getEmpList',{}).then(res=>{
						  let data = res.data
						  this.shopUser = data.result
			})
		},
		editRow(row){
			this.addTitle = '编辑'
			for(let i in this.form){
				this.form[i] = row[i]
			}
			this.formShow = true
		
		},
		addBtn(){
			this.formShow = true
			this.form = {
				id:null,
				group_name:"",
				owner_id:"",
			}
		},
		confirm(){
		        let params = {
		        	dd:this.form,
					group_ids:this.group_ids
		        }
				this.$api.post('/sadmin/addEditQyWxGroup',params).then(res=>{
					  if(res.code==200){
					  	this.$message.success('操作成功')
					  	this.formShow = false
					  	this.lodeList()
					  }
				})
		},
		delRow(id){
			this.$confirm('确定删除', '提示', {
					  confirmButtonText: '确定',
					  cancelButtonText: '取消',
					  type: 'warning'
					}).then(() => {
						let params = {
							dd:{id}
						}
					  this.$api.post('/sadmin/delQyWxGroup',params).then(res=>{
					  	  if(res.code==200){
					  	  	this.lodeList()
					  	  }
					  })
			  })
	   },
      lodeList(){
		  let params = {
		          	page:this.page,
		          	pageSize:this.pageSize,
		    }
		 
		  this.$api.post('/sadmin/getQyWxGroupList',params).then(res=>{
			  let data = res.data
			  this.page_totle = data.count
			  this.list = data.result
		  })
	  }
      
    }
  }
</script>
